package com.blindBox.front.handler.verify.loginVerifyImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.blindBox.front.commonResult.MsgBackToFront;
import com.blindBox.front.dao_pojo.User;
import com.blindBox.front.service.UserService;
import com.blindBox.front.handler.verify.Verify;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

//检验用户账号登录的类
@Component("uAccountVerify")
public class UserLoginByAccountVerify implements Verify<MsgBackToFront>
{
    @Autowired
    private UserService userService;
    @Override
    public MsgBackToFront verify(Object obj)
    {
        User user=(User) obj;
        //校验当前用户在数据库中是否存在，如果不存在，则校验失败
        User ret = userService.getOne(new QueryWrapper<User>().eq("uname", user.getUname()).eq("upwd", user.getUpwd()));
        if(ret!=null)
        {
            //检验用户是否被封号
            if(ret.getFlag()==1)
            {
                return new MsgBackToFront(null,MsgBackToFront.USER_NO_RIGHT);
            }
            //如果存在则校验成功
            return new MsgBackToFront(null,MsgBackToFront.HANDLE_SUCCESS);
        }
        //用户名或密码错误
        return new MsgBackToFront(null,MsgBackToFront.LOGIN_ERROR);
    }
}
